import 'package:sainbainu/common/apis/content_api.dart';
import 'package:sainbainu/common/models/request/content_request.dart';
import 'package:sainbainu/common/models/request/pager_request.dart';
import 'package:sainbainu/common/models/request/resource_request.dart';
import 'package:sainbainu/common/models/response/content_response.dart';

class ContentRepository {
  final ContentApi _contentApi;

  ContentRepository(this._contentApi);

  /// 发布
  Future<Map<String, dynamic>> create(ContentRequest contentRequest) async {
    var res = await _contentApi.create(contentRequest.toJson());
    return res;
  }

  /// 推荐列表
  Future<ContentListResponse> recommentList(PagerRequest pagerRequest) async {
    var res = await _contentApi.recommentList(pagerRequest.toJson());
    return ContentListResponse.fromJson(res);
  }

  /// 关注列表
  Future<ContentListResponse> followList(PagerRequest pagerRequest) async {
    var res = await _contentApi.followList(pagerRequest.toJson());
    return ContentListResponse.fromJson(res);
  }

  /// 小组推荐帖子列表
  Future<ContentListResponse> groupRecommentContentList(
    PagerRequest pagerRequest,
  ) async {
    var res = await _contentApi.groupRecommentContentList(
      pagerRequest.toJson(),
    );
    return ContentListResponse.fromJson(res);
  }

  /// 我的小组帖子列表
  Future<ContentListResponse> myGroupContentList(
    PagerRequest pagerRequest,
  ) async {
    var res = await _contentApi.myGroupContentList(
      pagerRequest.toJson(),
    );
    return ContentListResponse.fromJson(res);
  }

  /// 点赞
  Future<Map<String, dynamic>> giveAdd(ResourceRequest resourceRequest) async {
    var res = await _contentApi.giveAdd(resourceRequest.toJson());
    return res;
  }

  /// 取消点赞
  Future<Map<String, dynamic>> giveCancel(
      ResourceRequest resourceRequest) async {
    var res = await _contentApi.giveCancel(resourceRequest.toJson());
    return res;
  }

  /// 点赞列表
  Future<ContentListResponse> giveList(PagerRequest pagerRequest) async {
    var res = await _contentApi.giveList(pagerRequest.toJson());
    return ContentListResponse.fromJson(res);
  }

  /// 收藏
  Future<Map<String, dynamic>> collectionAdd(
      ResourceRequest resourceRequest) async {
    var res = await _contentApi.collectionAdd(resourceRequest.toJson());
    return res;
  }

  /// 取消收藏
  Future<Map<String, dynamic>> collectionCancel(
      ResourceRequest resourceRequest) async {
    var res = await _contentApi.collectionCancel(resourceRequest.toJson());
    return res;
  }

  /// 收藏列表
  Future<ContentListResponse> collectionList(PagerRequest pagerRequest) async {
    var res = await _contentApi.collectionList(pagerRequest.toJson());
    return ContentListResponse.fromJson(res);
  }

  /// 帖子详情
  Future<ContentResponse> contentDetail(int noteId) async {
    var res = await _contentApi.contentDetail({'noteId': noteId});
    return ContentResponse.fromJson(res['data']);
  }

  /// 我的作品列表
  Future<ContentListResponse> myList(PagerRequest pagerRequest) async {
    var res = await _contentApi.myList(pagerRequest.toJson());
    return ContentListResponse.fromJson(res);
  }

  /// 删除帖子
  Future<Map<String, dynamic>> del(int noteId) async {
    var res = await _contentApi.del({'noteId': noteId});
    return res;
  }

  /// 新增浏览
  Future<Map<String, dynamic>> viewAdd(ResourceRequest resourceRequest) async {
    var res = await _contentApi.viewAdd(resourceRequest.toJson());
    return res;
  }

  /// 新增分享
  Future<Map<String, dynamic>> shareAdd(ResourceRequest resourceRequest) async {
    var res = await _contentApi.shareAdd(resourceRequest.toJson());
    return res;
  }
}
